<template>
  <div class="finance-card" v-if="!userFlow.loading">
    <!-- 卡片头部 -->
    <div class="card-header">
      <Icon name="balance-o"
        class="header-icon" />
      <h3>资金概览</h3>
    </div>

    <!-- 数据展示区 -->
    <div class="data-grid">
      <div class="data-item">
        <div class="item-label">
          <Icon name="cash-back-record-o"
            class="van-icon" />
          <span>流水总收入</span>
        </div>
        <div class="item-value">
          {{ userFlow.data.totalRecordedAmount }}
        </div>
      </div>

      <div class="data-item">
        <div class="item-label">
          <Icon name="calendar-o"
            class="van-icon" />
          <span>今日收入</span>
        </div>
        <div class="item-value">
          {{ userFlow.data.totalAmountToday }}
        </div>
      </div>

      <div class="data-item">
        <div class="item-label">
          <Icon name="gold-coin-o"
            class="van-icon" />
          <span>总提现金额</span>
        </div>
        <div class="item-value">
          {{ userFlow.data.totalWithdrawAmount }}
        </div>
      </div>
    </div>

    <Button type="primary" block round
      class="withdraw-btn"
      :loading="userFlow.loading"
      @click="$router.replace({ name: 'WithdrawAction' })">
      <Icon name="cash-back-record"
        class="van-icon" />
      立即提现
    </Button>
  </div>
  <Skeleton v-if="userFlow.loading" :row="3" />
</template>
<script setup lang="ts">
import {
  Button, Icon,
  Skeleton,
} from 'vant';
import { onMounted } from 'vue';

import useUserStore from '@/stores/user.store';

import useTransaction from '../hooks/useTransaction';

const userStore = useUserStore();
const {
  userFlow, fetchSummary,
} = useTransaction();

onMounted(async () => {
  await userStore.fetchUserInfo();
  await fetchSummary();
});
</script>
<style lang="less" scoped>
.finance-card {
  background: var(--van-background-2);
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 2px 8px var(--van-box-shadow);
  margin: 12px;
}

.card-header {
  display: flex;
  align-items: center;
  margin-bottom: 20px;

  .header-icon {
    font-size: 24px;
    color: var(--van-primary-color);
    margin-right: 8px;
  }

  h3 {
    margin: 0;
    font-size: 18px;
    color: var(--van-text-color);
  }
}

.data-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 20px;

  .data-item {
    background: var(--van-background);
    padding: 12px;
    border-radius: 8px;
    text-align: center;

    .item-label {
      display: flex;
      align-items: center;
      justify-content: center;
      flex-wrap: nowrap;
      font-size: 12px;
      gap: 2px;
      color: var(--van-text-color-2);
      margin-bottom: 6px;

      .van-icon {
        font-size: 16px;
      }

      span {
        text-wrap: nowrap;
      }
    }

    .item-value {
      font-size: 15px;
      font-weight: 600;
      color: var(--van-primary-color);
    }
  }
}

.withdraw-btn {
  box-shadow: 0 2px 4px rgba(var(--van-primary-color-rgb), 0.2);

  .van-icon {
    margin-right: 6px;
  }
}
</style>
